package com.example.sso.server;

import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.sign.SaSignUtil;
import cn.dev33.satoken.util.SaResult;
import com.yky.config.SaTokenDaoDatabase;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 业务聚合
 *
 * @version [V2.0]
 * @package com.example.sso.server;
 * @description:[用一句话描述该文件做什么]
 * @author: [zhuben]
 * @date: [2024-01-23 18:24]
 * @copyright: 2024 echovin.com
 */

@RestController
public class UserInfoController {
    @Resource
    private SaTokenDaoDatabase saTokenDaoDatabase;

    @RequestMapping("/sso/getData")
    public SaResult getData(String apiType, String loginId) {
        System.out.println("---------------- 获取数据 ----------------");
        System.out.println("apiType=" + apiType);
        System.out.println("loginId=" + loginId);

        // 校验签名：只有拥有正确秘钥发起的请求才能通过校验
        SaSignUtil.checkRequest(SaHolder.getRequest());

        // 自定义返回结果（模拟）
        return SaResult.ok()
                .set("id", loginId)
                .set("name", "LinXiaoYu")
                .set("sex", "女")
                .set("age", 18);
    }

    @GetMapping("/sso/set")
    public void setSaTokenDao(String type){
        saTokenDaoDatabase.setType(type);
    }
}
